package com.test.mchelepesa.util_rice.http_rice;

import android.text.TextUtils;
import android.util.Log;

import com.test.mchelepesa.constant_rice.Constant_rice;
import com.test.mchelepesa.util_rice.StringUtil_rice;

import java.net.InetAddress;

public class HttpDnsV2 {
    public void lookupSys2(String httpUrl, Http3DnsCallback callback) {
        final String HOST = httpUrl.replaceFirst("^(https?://)", "");
        try {
            InetAddress[] addresses = InetAddress.getAllByName(HOST);
            for (InetAddress address : addresses) {
                String ipAddress = address.getHostAddress();
                if (!TextUtils.isEmpty(ipAddress)) {
                    if (Constant_rice.Debug)
                        Log.d(HttpDnsV2.class.getSimpleName(), "lookup: " + ipAddress);
                    callback.onResult(ipAddress);
                    return;
                }
            }

            callback.onFailed("");

        } catch (Exception e) {
            StringUtil_rice.printException(e);
            callback.onFailed(e.getMessage());
        }
    }

    public interface Http3DnsCallback {
        void onResult(String ipAddr);

        //tag2025
        void onFailed(String msg);
    }
}
